/* rewarp01.p - REPETITIVE                                                    */
/* Copyright 1986-2011 QAD Inc., Santa Barbara, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Id:: rewarp01.p 2366 2010-11-10 01:47:19Z zzh                          $: */
/* $Revision: 1.6.1.6 $                                                         */
/*V8:ConvertMode=FullGUIReport                                                */
/* REVISION: 7.3      LAST MODIFIED: 03/03/94   BY: WUG *GN77*                */
/* REVISION: 7.3      LAST MODIFIED: 02/14/96   BY: jym *G1N8*                */
/* REVISION: 7.3      LAST MODIFIED: 04/03/96   BY: jym *G1S7*                */
/* REVISION: 8.6      LAST MODIFIED: 10/11/97   BY: bvm *K0S7*                */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 11/17/99   BY: *N04H* Vivek Gogte        */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb                */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Old ECO marker removed, but no ECO header exists *K0S7*                    */
/* Revision: 1.6.1.4  BY: Hiral Kadakia DATE: 07/24/01 ECO: *N10F* */
/* Revision: 1.6.1.6.3.1  BY: Paul Donnelly (SB) DATE: 06/28/03 ECO: *Q00K* */
/*-Revision end---------------------------------------------------------------*/

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* WIP ADJUST ANALYSIS REPORT                                                 */

{us/mf/mfdtitle.i "99 "}
{us/wo/woconsdf.i}

{us/re/revars.i}
define buffer ophist for op_hist.
define variable dept           like wc_dept.
define variable dept1          like wc_dept  label "To".
define variable effdate        as   date     label "Effective".
define variable effdate1       as   date     label "To".
define variable emp            like op_emp.
define variable emp1           like op_emp   label "To".
define variable line           like wo_line.
define variable line1          like wo_line  label "To".
define variable lot            like wo_lot.
define variable lot1           like wo_lot   label "To".
define variable mch            like wc_mch.
define variable mch1           like wc_mch   label "To".
define variable part           like wo_part.
define variable part1          like wo_part  label "To".
define variable reason         like op_rsn.
define variable reason1        like op_rsn   label "To".
define variable shift          like op_shift.
define variable shift1         like op_shift label "To".
define variable site           like wo_site.
define variable site1          like wo_site  label "To".
define variable wkctr          like wc_wkctr.
define variable wkctr1         like wc_wkctr label "To".
define variable qty_cumproc    like wr_qty_cumproc
   column-label "Processed Qty".
define variable qty_cumadj     like wr_qty_cumoadj
   column-label "Adjust Qty".
define variable wrdesc         like wr_desc.
define variable ptdesc         like pt_desc1.
define variable percent_adjust as   decimal decimals 2 format "->,>>9.99%"
   column-label "Adjust!Percent".
define variable altpart   like ptal_alt_part no-undo.
define variable altpart1  like ptal_alt_part label "To" no-undo.
define variable fdisplayalt    as   logical no-undo.
define variable first_display  as   log.
define  variable order_type_key  like lngd_key1 initial "0".
define  variable c-lngd-dataset like lngd_det.lngd_dataset
   initial "wo_mstr" no-undo.
define variable orderType as character format "x(9)" label "Include Repetitive/Discrete/Both" no-undo.
form
   lot                 colon 20
   lot1                colon 45
   part                colon 20
   part1               colon 45
   site                colon 20
   site1               colon 45
   line                colon 20
   line1               colon 45
   reason              colon 20
   reason1             colon 45
   wkctr               colon 20
   wkctr1              colon 45
   mch                 colon 20
   mch1                colon 45
   dept                colon 20
   dept1               colon 45
   shift               colon 20
   shift1              colon 45
   emp                 colon 20
   emp1                colon 45
   effdate             colon 20
   effdate1            colon 45
   altpart     colon 20
   altpart1    colon 45 skip(1)
   orderType   colon 45  skip
with frame a side-labels width 80.

/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

find first gl_ctrl  where gl_ctrl.gl_domain = global_domain no-lock.

for first lngd_det where lngd_dataset = c-lngd-dataset
   and lngd_field   = "orderType"
   and lngd_lang    = global_user_lang
   and lngd_key1    = order_type_key
no-lock:
end.

if available lngd_det then
   orderType = lngd_key2.
else
   orderType = "".

{us/wb/wbrp01.i}

repeat:
   if lot1 = hi_char
      then
      lot1 = "".
   if part1 = hi_char
      then
      part1 = "".
   if site1 = hi_char
      then
      site1 = "".
   if line1 = hi_char
      then
      line1 = "".
   if reason1 = hi_char
      then
      reason1 = "".
   if wkctr1 = hi_char
      then
      wkctr1 = "".
   if mch1 = hi_char
      then
      mch1 = "".
   if dept1 = hi_char
      then
      dept1 = "".
   if shift1 = hi_char
      then
      shift1 = "".
   if emp1 = hi_char
      then
      emp1 = "".
   if effdate = low_date
      then
      effdate = ?.
   if effdate1 = hi_date
      then
      effdate1 = ?.
   if altpart1   = hi_char  then altpart1  = "".

   if c-application-mode <> 'web'
      then
   update
      lot
      lot1
      part
      part1
      site
      site1
      line
      line1
      reason
      reason1
      wkctr
      wkctr1
      mch
      mch1
      dept
      dept1
      shift
      shift1
      emp
      emp1
      effdate
      effdate1
      altpart
      altpart1
      orderType
   with frame a

      editing:
      if frame-field = "orderType" then do:
         {us/mf/mfnp05.i lngd_det lngd_det
            "lngd_dataset   = c-lngd-dataset
              and lngd_field  = 'orderType'
              and lngd_lang   = global_user_lang"
            lngd_key2 "input orderType" }
         if recno <> ? then
         display lngd_key2 @ orderType
         with frame a.
      end.
      else do:
         status input.
         readkey.
         apply lastkey.
      end.

   end.

   {us/wb/wbrp06.i &command = update
      &fields  = " lot     lot1     part   part1   site
        site1   line     line1  reason  reason1
        wkctr   wkctr1   mch    mch1    dept
        dept1   shift    shift1 emp     emp1
        effdate effdate1 altpart altpart1 orderType"
      &frm = "a"}

   if (c-application-mode <> 'web') or
      (c-application-mode = 'web' and
      (c-web-request begins 'data'))
   then do:

      bcdparm = "".
      {us/mf/mfquoter.i lot}
      {us/mf/mfquoter.i lot1}
      {us/mf/mfquoter.i part}
      {us/mf/mfquoter.i part1}
      {us/mf/mfquoter.i site}
      {us/mf/mfquoter.i site1}
      {us/mf/mfquoter.i line}
      {us/mf/mfquoter.i line1}
      {us/mf/mfquoter.i reason}
      {us/mf/mfquoter.i reason1}
      {us/mf/mfquoter.i wkctr}
      {us/mf/mfquoter.i wkctr1}
      {us/mf/mfquoter.i mch}
      {us/mf/mfquoter.i mch1}
      {us/mf/mfquoter.i dept}
      {us/mf/mfquoter.i dept1}
      {us/mf/mfquoter.i shift}
      {us/mf/mfquoter.i shift1}
      {us/mf/mfquoter.i emp}
      {us/mf/mfquoter.i emp1}
      {us/mf/mfquoter.i effdate}
      {us/mf/mfquoter.i effdate1}
      {us/mf/mfquoter.i altpart}
      {us/mf/mfquoter.i altpart1}
      {us/mf/mfquoter.i orderType}

      if lot1 = ""
         then
         lot1 = hi_char.
      if part1 = ""
         then
         part1 = hi_char.
      if site1 = ""
         then
         site1 = hi_char.
      if line1 = ""
         then
         line1 = hi_char.
      if reason1 = ""
         then
         reason1 = hi_char.
      if wkctr1 = ""
         then
         wkctr1 = hi_char.
      if mch1 = ""
         then
         mch1 = hi_char.
      if dept1 = ""
         then
         dept1 = hi_char.
      if shift1 = ""
         then
         shift1 = hi_char.
      if emp1 = ""
         then
         emp1 = hi_char.
      if effdate = ?
         then
         effdate = low_date.
      if effdate1 = ?
         then
         effdate1 = hi_date.
      if altpart1 = "" then altpart1  = hi_char.

   end.

   for first lngd_det where
      lngd_dataset     = c-lngd-dataset
      and lngd_field       = "orderType"
      and lngd_lang        = global_user_lang
      and lngd_key2 = orderType
   no-lock:
   end.
   if not available lngd_det
   then do:

      /* MUST BE (S)cheduled or (D)iscrete or (B)oth */
      {us/bbi/pxmsg.i &MSGNUM=10346 &ERRORLEVEL=4}

      if c-application-mode = "WEB"
         then
         return.

      else
      next-prompt
         orderType with frame a.
      undo,retry.
   end.
   order_type_key=lngd_key1.

   /* OUTPUT DESTINATION SELECTION */
   {us/gp/gpselout.i &printType = "printer"
      &printWidth = 132
      &pagedFlag = " "
      &stream = " "
      &appendToFile = " "
      &streamedOutputToTerminal = " "
      &withBatchOption = "yes"
      &displayStatementType = 1
      &withCancelMessage = "yes"
      &pageBottomMargin = 6
      &withEmail = "yes"
      &withWinprint = "yes"
      &defineVariables = "yes"}
   {us/bbi/mfphead.i}

   form
   with frame detail width 132 no-box down.

   /* SET EXTERNAL LABELS */
   setFrameLabels(frame detail:handle).

   for each op_hist no-lock
         where op_hist.op_domain = global_domain and  op_wo_lot     >= lot
         and   op_wo_lot     <= lot1
         and   op_part       >= part
         and   op_part       <= part1
         and   op_site       >= site
         and   op_site       <= site1
         and   op_line       >= line
         and   op_line       <= line1
         and   op_rsn_adjust >= reason
         and   op_rsn_adjust <= reason1
         and   op_wkctr      >= wkctr
         and   op_wkctr      <= wkctr1
         and   op_mch        >= mch
         and   op_mch        <= mch1
         and   op_dept       >= dept
         and   op_dept       <= dept1
         and   op_shift      >= shift
         and   op_shift      <= shift1
         and   op_emp        >= emp
         and   op_emp        <= emp1
         and   op_date       >= effdate
         and   op_date       <= effdate1
         and   can-do(advrep_optypes,op_type)
         and op_qty_adjust <> 0
         and ((altpart = "" and altpart1 = hi_char)
         or can-find(first ptal_mstr where ptal_mstr.ptal_domain = global_domain
         and ptal_part             = op_part
         and ptal_alt_part         >= altpart
         and ptal_alt_part         <= altpart1
         and ptal_active))
         and (order_type_key = {&MFG_TYPE_DISCRETE_AND_REPETITIVE}
         or can-find(first wo_mstr where wo_mstr.wo_domain = global_domain
         and wo_lot            = op_wo_lot
         and (wo_mfg_type= order_type_key)))
         use-index op_date
         break by op_site by op_part by op_wo_op by op_line
         by op_rsn_adjust
      with width 132 no-box:

      for first wo_mstr where wo_domain=global_domain and wo_lot=op_wo_lot no-lock:
      qty_cumadj = op_qty_adjust.
      end.

      for each ptal_mstr where ptal_mstr.ptal_domain = global_domain
            and ptal_part             = op_part
            and ptal_active
         no-lock:
      end.

      accumulate qty_cumadj (sub-total by op_rsn_adjust).

      if first-of(op_line)
      then do:
         qty_cumproc = 0.

         do for ophist:
            for each ophist no-lock
                  where ophist.op_domain = global_domain and  op_wo_lot >= lot
                  and op_wo_lot   <= lot1
                  and op_site      = op_hist.op_site
                  and op_part      = op_hist.op_part
                  and op_wo_op     = op_hist.op_wo_op
                  and op_line      = op_hist.op_line
                  and op_wkctr    >= wkctr
                  and op_wkctr    <= wkctr1
                  and op_mch      >= mch
                  and op_mch      <= mch1
                  and op_dept     >= dept
                  and op_dept     <= dept1
                  and op_shift    >= shift
                  and op_shift    <= shift1
                  and op_emp      >= emp
                  and op_emp      <= emp1
                  and op_date     >= effdate
                  and op_date     <= effdate1
                  and ((altpart = "" and altpart1 = hi_char)
                  or can-find(first ptal_mstr where ptal_mstr.ptal_domain = global_domain
                  and ptal_part             = op_part
                  and ptal_alt_part         >= altpart
                  and ptal_alt_part         <= altpart1
                  and ptal_active))
                  and (order_type_key = {&MFG_TYPE_DISCRETE_AND_REPETITIVE}
                  or can-find(first wo_mstr where wo_mstr.wo_domain = global_domain
                  and wo_lot            = op_wo_lot
                  and (wo_mfg_type= order_type_key)))
                  and can-do(advrep_optypes,op_type):
               qty_cumproc = qty_cumproc + op_qty_comp.
            end.
         end.

         first_display = yes.
      end.

      if last-of(op_rsn_adjust)
      then do:

         if first_display
         then do:
            display
               op_site
               op_part format "x(28)"
               op_wo_op
               op_line
               qty_cumproc
            with frame detail.

            first_display = no.
            fdisplayalt = yes.
         end.

         percent_adjust =
         ((accum sub-total by op_rsn_adjust qty_cumadj) * 100) /
            qty_cumproc.

         for first rsn_ref
            where rsn_ref.rsn_domain = global_domain and  rsn_type = "adjust"
            and   rsn_code = op_rsn_adjust
         no-lock:
         end. /* FOR FIRST rsn_ref */

         display
            space(4)
            op_rsn_adjust          column-label "Adj Reason"
            rsn_desc               when (available rsn_ref)
            accum sub-total        by    op_rsn_adjust qty_cumadj @ qty_cumadj
            percent_adjust         when (percent_adjust <> ?)
         with frame detail.
         down 1 with frame detail.

         if available(ptal_mstr) then
      do:
            if fdisplayalt = yes then do:
               display getTermLabel("ALT_NUMBER",8) + ": " + ptal_alt_part @ op_part with frame detail.
               fdisplayalt = no.
               if last-of(op_line) then down 1 with frame detail.
            end.
         end.

      end.

      if last-of(op_line)
         then
   down 1 with frame detail.

      {us/mf/mfrpchk.i}
   end.

   {us/mf/mfrtrail.i}
end.

{us/wb/wbrp04.i &frame-spec = a}

